home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
C_QNA.ARJ
/
CLASSPTR.TCP
< prev
next >
Wrap
Text File
|
1991-04-01
|
717b
|
24 lines
QUESTION: I need to create a pointer to member function but have not
been successful. How is this done?
ANSWER: The following is an example of how a pointer to a member
function may be created and used:
#include <stdio.h>
class testclass {
public:
void test(int x) { printf("-> %d <-", x); }
};
void main(void)
{
testclass xxx;
void (testclass::*p_func) (int); // p_func is type pointer to member
// function accepting an int and
// returning void
p_func = testclass::test; // assign p_func the address of test
(xxx.*p_func) (3); // call test
}